package com.coolw.thread.test;

/**
 * MyThread7
 *
 * @author coolw
 * @date 2024/5/8 19:10
 */
public class MyThread7 {

    private static final Object OBJECT1 = new Object();
    private static final Object OBJECT2 = new Object();

    public static void main(String[] args) throws InterruptedException {

        Thread thread1 = new Thread(() -> {
            synchronized (OBJECT1) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (OBJECT2) {
                    System.out.println(Thread.currentThread().getName());
                }
            }
        });

        Thread thread2 = new Thread(() -> {
            synchronized (OBJECT2) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (OBJECT1) {
                    System.out.println(Thread.currentThread().getName());
                }
            }
        });

        thread1.start();
        thread2.start();
    }
}
